#include <cstdio>
struct tag
{
    int max;
    int index; //left boundary
} dp[10001];
int seq[10001] = {0};
int main()
{
    int K;
    scanf("%d", &K);
    int flag = 1; //标记是否为全负
    for (int i = 1; i <= K; ++i)
    {
        scanf("%d", seq + i);
        if (seq[i] >= 0)
            flag = 0;
    }
    if (1 == flag)
    {
        printf("0 %d %d\n", seq[1], seq[K]);
        return 0;
    }
    //boundary
    dp[1].index = 1;
    dp[1].max = seq[1];
    //State transition equation
    for (int i = 2; i <= K; ++i)
    {
        if (dp[i - 1].max > 0)
        {
            dp[i].max = dp[i - 1].max + seq[i];
            dp[i].index = dp[i - 1].index;
        }
        else
        {
            dp[i].max = seq[i];
            dp[i].index = i;
        }
    }
    int index;
    int max = -1;
    for (int i = 1; i <= K; ++i)
    {
        if (dp[i].max > max)
        {
            index = i;
            max = dp[i].max;
        }
    }
    printf("%d %d %d\n", max, seq[dp[index].index], seq[index]);
    return 0;
}